package com.brainhealth.web.controller.customer;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.brainhealth.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.brainhealth.common.annotation.Log;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.enums.BusinessType;
import com.brainhealth.customer.domain.CustomerReportTime;
import com.brainhealth.customer.service.ICustomerReportTimeService;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.common.core.page.TableDataInfo;

/**
 * 会员每次训练报告Controller
 * 
 * @author wolong
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/customer/reportTime")
public class CustomerReportTimeController extends BaseController
{
    @Autowired
    private ICustomerReportTimeService customerReportTimeService;

    /**
     * 查询会员每次训练报告列表
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerReportTime customerReportTime)
    {
        startPage();
        List<CustomerReportTime> list = customerReportTimeService.selectCustomerReportTimeList(customerReportTime);
        return getDataTable(list);
    }

    /**
     * 导出会员每次训练报告列表
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:export')")
    @Log(title = "会员每次训练报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerReportTime customerReportTime)
    {
        List<CustomerReportTime> list = customerReportTimeService.selectCustomerReportTimeList(customerReportTime);
        ExcelUtil<CustomerReportTime> util = new ExcelUtil<CustomerReportTime>(CustomerReportTime.class);
        util.exportExcel(response, list, "会员每次训练报告数据");
    }

    /**
     * 获取会员每次训练报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:query')")
    @GetMapping(value = "/{customerReportTimeId}")
    public AjaxResult getInfo(@PathVariable("customerReportTimeId") Long customerReportTimeId)
    {
        return success(customerReportTimeService.selectCustomerReportTimeByCustomerReportTimeId(customerReportTimeId));
    }

    /**
     * 新增会员每次训练报告
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:add')")
    @Log(title = "会员每次训练报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerReportTime customerReportTime)
    {
        return toAjax(customerReportTimeService.insertCustomerReportTime(customerReportTime));
    }

    /**
     * 修改会员每次训练报告
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:edit')")
    @Log(title = "会员每次训练报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerReportTime customerReportTime)
    {
        return toAjax(customerReportTimeService.updateCustomerReportTime(customerReportTime));
    }

    /**
     * 删除会员每次训练报告
     */
    @PreAuthorize("@ss.hasPermi('customer:reportTime:remove')")
    @Log(title = "会员每次训练报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerReportTimeIds}")
    public AjaxResult remove(@PathVariable Long[] customerReportTimeIds)
    {
        return toAjax(customerReportTimeService.deleteCustomerReportTimeByCustomerReportTimeIds(customerReportTimeIds));
    }

    /**
     * 获取会员每次的报告
     */
    @Anonymous
    @PostMapping("/getCustomerReportTime")
    public AjaxResult getCustomerReportTime(@RequestBody Map<String, Object> map)
    {
        Long customerReportTimeId = Long.valueOf(map.get("customerReportTimeId").toString());
        CustomerReportTime customerReportTime = customerReportTimeService.selectCustomerReportTimeByCustomerReportTimeId(customerReportTimeId);
        return AjaxResult.success(customerReportTime);
    }
}
